/**
 * Copyright © 2011 looty - Textoo
 * @link http://www.textoo.org
 * @link http://code.google.com/p/textoo/
 * @author lab9 - Bertrand Larrieu
 * @mail lab9.fr@gmail.com
 * @version 2.0
 */

package org.looty.core.textoo.context.style 
{
	import flash.text.*;
	import flash.utils.*;

	public class TextooStyleSheet extends StyleSheet
	{
		
		
		/**
		 * to be able to extends css capabilities (text-transform for example), a custom html parser would be needed.
		 * problem using EX4 parser, it will generate an error when xml is not correctly close (which doesn't occur with textfield parsing.
		 * so, best solution would be to use regexp, but require to build a fully functionnal parser. 
		 **/ 
		
		
		private var _title			:String;
		
		public function TextooStyleSheet(title:String, styleSheet:StyleSheet = null) 
		{
			_title = title;
			
			super();			
		}
		
		public function merge(styleSheet:StyleSheet):void
		{
			for each (var styleName:String in styleSheet.styleNames) setStyle(styleName, styleSheet.getStyle(styleName));
		}
		
		override public function transform(formatObject:Object):flash.text.TextFormat 
		{
			//for (var prop:String in formatObject) trace("prop", prop, formatObject[prop]);
			
			var format:TextFormat = super.transform(formatObject);
			var tFormat:TextooFormat = new TextooFormat(format.font, format.size, format.color, format.bold, format.italic, format.underline, format.url, format.target, format.align, format.leftMargin, format.rightMargin, format.indent, format.leading, formatObject["textTransform"]);
			
			return tFormat;
		}
		
		public function get title():String 
		{
			return _title;
		}
		
		public function dispose():void
		{
			
		}
		
		override public function toString():String 
		{
			return "[" + getQualifiedClassName(this) + "] title : " + _title; 
		}
		
		
	}

}